<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link th:href="@{/css/style.css}" rel="stylesheet" type="text/css" />
  <script type="text/javascript" th:src="@{/js/jquery.js}"></script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>采购管理</li>
    <li>商品管理</li>
    <li>修改</li>
  </ul>
</div>
<div class="formbody">
  <div class="formtitle"><span>商品信息</span></div>
  <form action="/purchase/cproduct/update" method="post">
    <input type="hidden" name="productId" th:value="${cproduct.productId}">
  <ul class="forminfo">
    <li>
      <label>品牌名称</label>
      <select class="dfselect" onchange="getbrands(this.value)" name="brandId" id="brandId">
        <!--<option value="0">请选择</option>
        <option th:each="cb :${cbrands}" th:value="${cb.brandId}" th:text="${cb.brandName}">联想</option>-->
      </select>
      <i>必选</i>
    </li>
    <li>
      <input type="hidden" name="namee" th:value="${name}" id="name">
      <input type="hidden" name="ti" id="ti" th:value="${cproduct.firmId}">
      <label>商品类型</label>
      <select class="dfselect" name="typeId" id="typeId">
        <option value="0">请选择</option>
      </select>
      <i>必选</i>
    </li>
    <li>
      <label>商品型号</label>
      <input name="productModel" type="text" th:value="${cproduct.productModel}" class="dfinput" />
      <i>必填，不能超过50个字符</i>
    </li>
    <li>
      <label>产商</label>
      <select class="dfselect" name="firmId" id="firmId">
        <option value="0">请选择</option>
      </select>
      <i>必选</i>
    </li>
    </li>
    <li>
      <label>单位</label>
      <input name="productUnit" type="text" th:value="${cproduct.productUnit}" class="dfinput" />
      <i>必填，不能超过10个字符</i>
    </li>
    <li>
      <label>单价</label>
      <input name="productPrice" th:value="${cproduct.productPrice}" type="text" class="dfinput" id="productPrice" />
      <i>必填，不能超过10个字符</i>
    </li>
    <li>
      <label>状态</label>
      <select class="dfselect" name="productStatus">
          <option value="1" th:selected="${cproduct.productStatus==1}">可用</option>
          <option value="2" th:selected="${cproduct.productStatus==2}">不可用</option>
        </select>
      <i>必选</i>
    </li>
    <li>
      <label>创建人</label>
      <input name="" type="text" th:value="${session.users.uname}" readonly="readonly" class="roinput" />
      <i>不能编辑</i>
    </li>
    <li>
      <label>创建时间</label>
      <input name="" type="text" th:value="${#dates.format(cproduct.createTime,'yyyy-MM-dd hh:mm:ss')}" readonly="readonly" class="roinput" />
      <i>不能编辑</i>
    </li>
    <li>
      <label>&nbsp;</label>
      <input name="" type="submit" class="btn" value="确定"/>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input name="" type="button" class="btn" value="返回" onclick="window.location.href='/purchase/cproduct/cplist'"/>
    </li>
  </ul>
  </form>
</div>
<script th:inline="javascript">
  $(function () {
    var num=$("select[class=dfselect]").val();
    getbrands(num);
  });

  function getbrands(num) {
    $.get("/erp/purchase/cproduct/ajaxtypes",{"brandid":num},function (data) {
      //alert(typeof(data));
      $("select[name=typeId]").html("");
      var options="<option value='0'>请选择</option>";
      $.each(data,function (i,e) {
        var a=[[${cproduct.typeId}]];
        if(e.typeId==a){
          options+="<option value='"+e.typeId+"'selected='selected'>"+e.typeName+"</option>";
        }else{
          options+="<option value='"+e.typeId+"'>"+e.typeName+"</option>";
        }
      });
      $("select[name=typeId]").append(options);
    },"json");
  }
  /*查询品牌*/
  function pai(){
    var a=$("#name").val()
    alert(a)
    $.ajax({
      url: "/purchase/cproduct/selectpai",
      type: "post",
      datatype: "json",
      async:false,
      success: function (data) {
        var str="<option value=\"\">请选择</option>"
        for (var i=0;i<data.length;i++){
          if (data[i].brandId==a) {
            str += "<option selected value=\"" + data[i].brandId + "\">" + data[i].brandName + "</option>"
          }else {
            str += "<option value=\"" + data[i].brandId + "\">" + data[i].brandName + "</option>"

          }
          }
        $("#brandId").html(str)
      }
    });
  }
  /*【品牌内容发生改变是触发的事件----查类型*/
  function ty() {
    $.ajax({
      url: "/purchase/cproduct/selecttype",
      data: {brandId: $("#brandId").val()},
      type: "post",
      datatype: "json",
      async:false,
      success: function (data) {
        var str = "<option value=''>请选择</option>"
        for (var i = 0; i < data.length; i++) {
          str += "<option selected value=\"" + data[i].typeId + "\">" + data[i].typeName + "</option>"
        }
        $("#typeId").html(str)
      }
    });
  }
  $("#brandId").change(function () {
    $.ajax({
      url: "/purchase/cproduct/selecttype",
      data: {brandId: $("#brandId").val()},
      type: "post",
      datatype: "json",
      async: false,
      success: function (data) {
        var str = "<option value=''>请选择</option>"
        for (var i = 0; i < data.length; i++) {
          str += "<option value=\"" + data[i].typeId + "\">" + data[i].typeName + "</option>"
        }
        $("#typeId").html(str)
      }
    });
  });
  /*查询厂商*/
  function chang(){
    $.ajax({
      url: "/purchase/cproduct/chang",
      type: "post",
      datatype: "json",
      async: false,
      success: function (data) {
        var str="<option value=''>请选择</option>"
        for (var i=0;i<data.length;i++){
          if (data[i].firmId==$("#ti").val()) {
            str += "<option selected value=\"" + data[i].firmId + "\">" + data[i].firmName + "</option>"
          }else {
            str += "<option value=\"" + data[i].firmId + "\">" + data[i].firmName + "</option>"
          }
        }
        $("#firmId").html(str)
      }
    });
  }
  $(function (){
    pai();
    ty();
    chang()
  })
</script>
</body>
</html>
